package com.metaverse.backend.utils;

import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.IdentifierGenerator;

import java.io.Serializable;

public class SnowflakeIdGenerator implements IdentifierGenerator {

    private final SnowflakeIdWorker snowflakeIdWorker;

    public SnowflakeIdGenerator() {
        this.snowflakeIdWorker = new SnowflakeIdWorker(0, 0);
    }

    @Override
    public Serializable generate(SharedSessionContractImplementor sharedSessionContractImplementor, Object o) throws HibernateException {
        return snowflakeIdWorker.nextId();
    }
}
